package cn.edu.scau.sec.caixiaoqing.composite.securitycomposite;

import java.util.ArrayList;

public class SecurityTestSuite implements SecurityTestCase {
    private ArrayList<SecurityTestCase> securityTestCaseList;

    public SecurityTestSuite(){
        securityTestCaseList = new ArrayList<>();
    }

    @Override
    public boolean test() {
        try {
            for (SecurityTestCase aCase :
                    securityTestCaseList) {
                boolean success = aCase.test();
                if (aCase instanceof AtomSecurityTestCase){
                    if (success) System.out.println("测试通过。");
                    else System.out.println("测试没有通过，请检查测试数据和被测试的方法，查找测试没有通过的原因。");
                }
            }
            return true;
        }
        catch (Exception e){
            System.out.println("出错了，错误名是"+e);
            return false;
        }
    }

    public void add(SecurityTestCase securityTestCase){
        if (securityTestCase != null) securityTestCaseList.add(securityTestCase);
    }

    public void remove(SecurityTestCase securityTestCase){
        if (securityTestCase != null) securityTestCaseList.remove(securityTestCase);
    }

    public SecurityTestCase getTestCase(int index){
        return securityTestCaseList.get(index);
    }
}
